package com.config;

import java.util.ArrayList;
import java.util.List;

import org.ajaxanywhere.AAFilter;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.context.annotation.Configuration;

/**
 * 
 * @author 北京八维博大科技 薛建新
 * @date 2022年7月28日 下午2:22:53
 * @Copyright 北京八维博大科技
 */
@Configuration
public class FilterConfig {
	// https://blog.csdn.net/momomoge/article/details/7333327
	@Bean
	public FilterRegistrationBean<AAFilter> filterRegistration() {
		var registration = new FilterRegistrationBean<AAFilter>();
		registration.setFilter(new AAFilter());
		List<String> urlList = new ArrayList<String>();
		urlList.add("/*");
		registration.setUrlPatterns(urlList);
		registration.setName("ajaxAnywhere");
//		registration.setOrder(1);
		return registration;
	}

/*	
	@Bean
	public static BeanFactoryPostProcessor beanFactoryPostProcessor(ApplicationContext applicationContext) {
		return new BeanFactoryPostProcessor() {

			@Override
			public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
				if (beanFactory instanceof BeanDefinitionRegistry) {
					try {
						BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
						ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(registry);
						scanner.setResourceLoader(applicationContext);
						scanner.scan("com.xue.test");
					} catch (Throwable e) {
						e.printStackTrace();
					}
				}

			}

		};
	}
*/	

}
